<!-- home主页 -->
<template>
  <div>
    <button-base :buttonText="'postDemo'" @buttonClick="postDemo"></button-base>
    <button-base :buttonText="'getDemo'" @buttonClick="getDemo"></button-base>
    <button-base
      :buttonText="'并发请求'"
      @buttonClick="testAllPost"
    ></button-base>
    <button-base :buttonText="'取消请求'" @buttonClick="cancel"></button-base>
  </div>
</template>

<script>
import buttonBase from "../components/button-base.vue";
// import http from "../utils/http";
// import  { getHasCancelToken, get, all, cancelRequest } from "../utils/http"
import {
  axiosRequest,
  removeAllRequest,
  axiosRequestAll,
} from "../utils/http2";
import api from "../utils/api";
export default {
  name: "home",
  components: {
    buttonBase,
  },
  data() {
    return {
      httpRequest: null,
      httpRequestList: [],
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
  methods: {
    postDemo() {
      axiosRequest("post", api.currentCulture, {}, { mid: 111 }, true);
      // await axiosTest();
      // // setTimeout(function(){ removeAllRequest(); },0);
      // removeAllRequest();
    },
    getDemo() {
      axiosRequest(
        "get",
        "/manager/control/images/1606814444936.jpg",
        {},
        {},
        true //是否要加入可取消请求的队列
      ).then((response) => {
        console.log(response);
      });
    },
    testAllPost() {
      let items = [
        {
          method: "post",
          url: api.currentCulture,
          params: {},
          data: { mid: 111 },
        },
      ];
      axiosRequestAll(items);
    },
    cancel() {
      removeAllRequest();
    },
  },
};
</script>
<style scoped>
</style>